package com.guigu.youxuan.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.youxuan.common.utils.PageUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.youxuan.pojo.MerchantInfo;
import com.guigu.youxuan.pojo.SysUsers;
import com.guigu.youxuan.service.IMerchantInfoService;
import com.guigu.youxuan.service.ISysUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liweixin
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/merchantInfo")
public class MerchantInfoController {
    @Autowired
    private IMerchantInfoService merchantInfoService;

    @Autowired
    private ISysUsersService sysUsersService;
    /**
     * SysUsers
     */
    /**
     * 商户查询所有
     * @param pageNo
     * @param pageSize
     * @param merchantInfo
     * @return
     */
    @RequestMapping("/queryAll/{pageNo}/{pageSize}")
    @ResponseBody
    public PageInfo<MerchantInfo> page(@PathVariable int pageNo,
                                       @PathVariable int pageSize,
                                       @RequestBody MerchantInfo merchantInfo) {
        PageInfo<MerchantInfo> pageInfo=this.merchantInfoService.getMerchantList(pageNo,pageSize,
                merchantInfo);
        System.out.println("pageInfo = " + pageInfo);
        return pageInfo;
    }

    /**
     *获取id
     * @param
     * @return
     */
    @RequestMapping("/getById/{merchantId}")
    @ResponseBody
    public MerchantInfo getById(int merchantId) {
        MerchantInfo merchantInfo = merchantInfoService.getById(merchantId);
        return merchantInfo;
    }

    /**
     * 修改
     * @param merchantInfo
     * @return
     */

    @RequestMapping("/updById")
    @ResponseBody
    public String updById(@RequestBody MerchantInfo merchantInfo) {
        System.out.println("merchantInfo = " + merchantInfo);
        boolean flag = merchantInfoService.updateById(merchantInfo);
        if (flag) {
            return "ok";
        }
        return "error";
    }

    /**
     *
     * @param merchantInfo
     * @return
     */
    @RequestMapping("delByMerchantId")
    @ResponseBody
    public String delBackUser(@RequestBody MerchantInfo merchantInfo) {
        merchantInfoService.delByMerchantId(merchantInfo);
        return "删除成功！";
    }


    /**
     *条件查询
     * @param merchantInfo
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping("/merchantInfoPage/{pageNo}/{pageSize}")
    @ResponseBody
    public PageUtils<MerchantInfo> merchantInfoFuHePage(
            @RequestBody MerchantInfo merchantInfo,
            @PathVariable int pageNo,
            @PathVariable int pageSize) {
        PageUtils<MerchantInfo> page = this.merchantInfoService.merchanrInfoFuHePage(merchantInfo,pageNo, pageSize);
        return page;
    }

    /**
     * 复核按钮按照id查所有
     * @param id
     * @return
     */
    @RequestMapping("/merchantInfoGetId/{id}")
    @ResponseBody
    public MerchantInfo designProcedureGetId(@PathVariable int id) {
        MerchantInfo merchantInfo = this.merchantInfoService.getById(id);
        return merchantInfo;
    }

    /**
     * dfsd
     * @param merchantInfo
     * @return
     */
    @RequestMapping("/merchantInfoFuHeOk")
    @ResponseBody
    public String storageCellReviewPassed(@RequestBody MerchantInfo merchantInfo) {
        merchantInfo.setCheckTag("S001-3");
        boolean flag = merchantInfoService.updateById(merchantInfo);
        if (flag) {
            return "correct";
        }
        return "error";
    }

    @RequestMapping("/selAddressList")
    @ResponseBody
    public List<MerchantInfo> selAddressNameList(){
        List<MerchantInfo> selAddressList=merchantInfoService.selAddress();
        return selAddressList;
    }
    /**
     * 商户入驻 添加
     * @param merchantInfo
     * @return
     */
    @RequestMapping("/MerchanInfoAdd/{id}")
    @ResponseBody
    public String MerchanInfoAdd(@RequestBody MerchantInfo merchantInfo,@PathVariable int id) {
        merchantInfo.setSysUsersId(id);
        merchantInfo.setCheckTag("S001-1");
        boolean flag = merchantInfoService.save(merchantInfo);
        if (flag) {
            return "correct";
        }
        return "error";
    }

    /**
     * 复核不成功
     * @param merchantInfo
     * @return
     */
    @RequestMapping("/merchantInfoFuHeNoOk")
    @ResponseBody
    public String storageCellReviewPassedNo(@RequestBody MerchantInfo merchantInfo) {
        merchantInfo.setCheckTag("S001-2");
        boolean flag = merchantInfoService.updateById(merchantInfo);
        if (flag) {
            return "correct";
        }
        return "error";
    }

    /**
     *商户资料维护获取id查所有
     * @param
     * @return
     */
    @RequestMapping("/selBySysId/{sysUsersId}")
    @ResponseBody
    public List<MerchantInfo> selBySysId(@PathVariable int sysUsersId) {
        List<MerchantInfo> merchantInfo = merchantInfoService.SelById(sysUsersId);
        return merchantInfo;
    }
}
